<!DOCTYPE html>
<html>
<head>
<head />
<div th:include="base-libs :: base-libs" />
<div th:include="common/yljg-modal :: yljg-modal" />
<title>服务项操作</title>
<style type="text/css">
.topBtn{
	float: right;
	margin-right:10px;
	margin-top:5px
}
</style>
</head>
<script th:inline="javascript">
	/**用户信息*/
	var userInfo = [[${userInfo}]];
</script>
<script type="text/javascript">
    var fwCache = StoreCache.removeCache("FWXX_INFO");
	$(function() {
		$(this).registerManagerPage({cacheTables:["TB_ZY_YBXM"],callback: initView});
	});

	function initView() {
	    if(!NFTJ_YBFWX){//能否添加医保服务项
			$("#FWLB option[value=04]").remove();
		}
		$("#xzYljg").on("click", function(){
			selectionId = $("#YLJGID").val();
			//页面层
			parent.layer.open({
			  type: 1,
			  area: ["80%", "500px"], //宽高
			  scrollbar: false,
			  resize: false,
			  title: '选择所属机构',
			  content: $("#yljgModal").html(),
			  btn: ["确定", "取消"],
			  success: function(layero, index){
				  initYljgTable(layero);
			  },
			  yes: function (index, layero) {
				  var info = $(layero).find("#yljgForm").datagrid("getSelected")
           		  $("#YLJGMC").val(info["YLJGMC"]);
 			   	  $("#YLJGID").val(info["PTJGID"]);
           		  parent.layer.close(index);//这块是点击确定关闭这个弹出层
              }
			});
		});
		$("#XZBLTR").hide();
		
		$("#SFLX").on("change", function(){
			var value = $(this).val();
			$("#SFBZ").show();
			$("#SFBZ").addClass("form-control");
            $(this).css("width","40%");
			if(value == ""){
				$("#FYDW").val("");
				$("#FYDWMC").text("");
			}
			else if(value == "01"){
				$("#FYDW").val("01");
				$("#FYDWMC").text("元/次");
			}
			else if(value == "02"){
				$("#FYDW").val("02");
				$("#FYDWMC").text("元/月");
			}
			else if(value == "03"){
				$("#FYDW").val("03");
				$("#FYDWMC").text("元");
			}else if(value == "04"){
				$("#SFBZ").hide();
				$("#SFBZ").removeClass("form-control");
				$("#SFBZ").val("");
				$("#FYDW").val("");
				$("#FYDWMC").text("");
				$(this).css("width","90%");
			}

		});
		
		/**保存按钮*/
		$("#btnSave").on("click", function(){
			if($(".form-control").QuickValidate()){
			    var SFLX = $("#SFLX").val();

				/**获取服务状态*/
				$.QuickRemote.AjaxFiledFormSubmit("managerForm", function(result) {
					var info = result["info"];
					if (result["state"]) {
						$.QuickAlert.alertNormal("操作成功！",{callback: function(){
							$.QuickUrlUtils.redirectUrl("index.html");
						}});
					} else {
						$.QuickAlert.alertFail({
							content : info["faultInfo"]
						});
					}
				},{ FWZT : "1", SFLX: SFLX});
			}
		});
		
		/**签约列表change事件*/
		$("#QYLB").on("change", function(){
			if($(this).val() == "02"){
				$("#FWLBTR").hide();
				$("#FWLB").removeClass("form-control");
				$("#FWLB").val("");
				$("#XZBLTR").show();
				$("#XZBL").addClass("form-control");
			}else{
				$("#XZBLTR").hide();
				$("#XZBL").removeClass("form-control");
				$("#XZBL").val("");
				$("#FWLBTR").show();
				$("#FWLB").addClass("form-control");
				//$("#FWLB").attr("quick-config", "label:'服务项类别', validateProxy:'notNull'");
			}
			if(fwCache.FWLB == "04"){
				$("#FWLB").trigger("change");
			}
		});

		/*服务项类别联动*/
		$("#FWLB").change(function(){
		    var val = this.value;
		    if(val == '04'){//医保类别
                $("#SFLX").val("01").attr("disabled","disabled").css("cursor","not-allowed").trigger("change");
                $(".fwxlbTd").removeAttr("colspan");
                $(".ybxmTd").show();
                $("#YBXMXMDM").addClass("form-control");
                $("#FWLB").css("width","90.6%");
			}else{
				$(".ybxmTd").hide();
				$("#YBXMXMDM").val("").removeClass("form-control");
				$(".fwxlbTd").attr("colspan","3");
				$("#SFLX").val("").removeAttr("disabled").css("cursor","default");
                $("#FWMC,#SFBZ").val("");
                $("#FWLB").css("width","96%");
			}
		})
        $("#FWLB").trigger("change");

		/*载入医保项目*/
		var ybxmArr = StoreCache.getCache("TB_ZY_YBXM").data;
		$.each(ybxmArr, function(){
		    //XMDJ==项目单价
		    var option = $("<option>").html(this.XMMC).attr("value",this.XMDM).data("XMDJ",this.XMDJ);
		    $("#YBXMXMDM").append(option);
		})
		/*医保项目联动*/
		$("#YBXMXMDM").change(function(){
			var select = $(this).find("option:selected");
			var ybxmMC = select.text(),
				ybxmXMDJ=select.data("XMDJ");
			$("#FWMC").val(ybxmMC);
			$("#SFBZ").val(ybxmXMDJ);
		})

        initData(); //载入数据
	}

    function initData() {
        $("#managerForm").attr("action", "save");
        /**赋值当前登录用户机构信息*/
        $("#YLJGMC").val(userInfo["YLJGMC"]);
        $("#YLJGID").val(userInfo["PTJGID"]);
        /**当前机构非平台时禁用选择机构*/
        if((userInfo["WSJGLBDM"]).substr(0,1) != "R"){
            $("#xzYljg").attr("disabled", "disabled");
        }
        /**加载服务项信息*/
        if(fwCache){
            fwCache["CJSJ"] = fwCache["CJSJ"].substr(0 ,10);
            $("#method").val("update");
            $("#managerForm").find(".dataField").each(function(){
                $(this).val(fwCache[$(this).attr("id")]);
            });
            $("#QYLB").trigger("change");
            $("#SFLX").trigger("change");
        }else{
            $("#CJSJ").val(new Date().Format("yyyy-MM-dd"));
            $("#FWID").val(createCurrentBm());
        }
    }

	/**返回按钮*/
	function btnBackHandler() {
		$.QuickUrlUtils.redirectUrl("index.html");
	}
	
	/**获取当前编码*/
	function createCurrentBm(){
		var currentBm = "";
		/**判断当前用户权限*/
		var currentUser = {"JGDM" : "000000"};
		if(currentUser["JGDM"] == "000000"){
			currentBm += "T";
		}else{
			currentBm += "A";
		}
		var date = new Date();
        currentBm += date.Format("yyyyMMddHHmmss")+ date.getMilliseconds(); //年月日时分秒毫秒
	    return currentBm;
	}

	/** 判断收费标准是否是数字 */
	function testSfbzIsNum(){
	    var val = $(this).val();
	    if(isNaN(val)){
			return "收费标准只能由数字组成";
		}
	}
</script>

<body class="easyui-layout">
	<div region="north" style="border: none; overflow: hidden;">
		<h4 class="h4-title" style="font-size: 18px;">
			服务项信息
			<button class="btn topBtn" style="float:right" type="button" onclick="btnBackHandler()">返回</button>
			<button class="btn topBtn" type="button" id="btnSave" >提交</button>
		</h4>
	</div>
	<div region="center" style="border: none">
		<div class="form-table-box" >
			<form id="managerForm" class="form-horizontal" >
				<div style="display: none;" >
					<input id="YLJGID" name="YLJGID" class="dataField"/>
					<input id="method" name="method" value="add"/>
				</div>
				<table class="form-table">
						<tr>
							<td class="td-text">
								<label>服务项编号：</label>
							</td>
							<td class="td-content">
								<input id="FWID" name="FWID" class="form-control dataField" type="text"
									readonly="readonly"	placeholder="服务项编号">
							</td>
							<td class="td-text">
								<label>创建时间：</label>
							</td>
							<td class="td-content" colspan="3">
								<input id="CJSJ" name="CJSJ"  readonly="readonly" class="form-control dataField" type="text"/>
							</td>
						</tr>
						
						<tr>
							<td class="td-text">
								<label>所属机构：</label>
							</td>
							<td class="td-content">
								<input id="YLJGMC" name="YLJGMC" class="form-control dataField" readonly="readonly"	
								quick-config="label:'医疗机构', validateProxy:'notNull length', length: '64'" style="width: 60%;display: inline-block;"/>
								<!-- 按钮触发模态框 -->
								<button style="width: 29%;" class="btn" type="button" id="xzYljg">选择机构</button>
							</td>
							<td class="td-text">
								<label>签约类别：</label>
							</td>
							<td class="td-content">
								<select id="QYLB" name="QYLB" class="form-control dataField" style="width:90%;"
								quick-config="label:'签约类别', validateProxy:'notNull'"
								cacheTable="TB_ZY_QY_TYPE">
								</select>
							</td>
						</tr>
						
						<tr id="FWLBTR">
							<td class="td-text">
								<label>服务项类别：</label>
							</td>
							<td class="td-content fwxlbTd">
								<select id="FWLB" name="FWLB" class="form-control dataField" style="width:90%;"
								quick-config="label:'服务项类别', validateProxy:'notNull'"
								cacheTable="TB_ZY_SERVICE_TYPE">
								</select>
							</td>
							<td class="td-text ybxmTd">
								<label>医保项目：</label>
							</td>
							<td class="td-content ybxmTd">
								<select id="YBXMXMDM" name="YBXMXMDM" class="form-control dataField" style="width:90%;"
										quick-config="label:'医保项目', validateProxy:'notNull'">
									<option value="">请选择</option>
								</select>
							</td>
						</tr>
						<tr id="XZBLTR">
							<td class="td-text">
								<label>是否选择病例：</label>
							</td>
							<td class="td-content" colspan="3">
								<select id="XZBL" name="XZBL" class="dataField cacheTable" style="width:96%;"
									quick-config="label:'选择病例', validateProxy:'notNull'">
									<option value="">请选择</option>
									<option value="1">是</option>
									<option value="0">否</option>
								</select>
							</td>
						</tr>
						
						<tr>
							<td class="td-text">
								<label>服务项名称：</label>
							</td>
							<td class="td-content">
								<input id="FWMC" name="FWMC" class="form-control dataField" type="text"
									   quick-config="label:'服务项名称', validateProxy:'notNull length', length: '100'"
									   placeholder="服务项名称">
							</td>
							<td class="td-text">
								<label>收费标准：</label>
							</td>
							<td class="td-content">
								<select id="SFLX" name="SFLX" class="form-control dataField cacheTable" style="width:40%;"
										quick-config="label:'收费标准', validateProxy:'notNull'"
										cacheTable="TB_ZY_SFLX">
								</select>
								<input id="SFBZ" name="SFBZ" class="form-control dataField" type="text" style="width:48%"
									   quick-config="label:' 收费标准', validateProxy:'testSfbzIsNum notNull length', length: '64'"
									   placeholder="收费标准">
								<span id="FYDWMC"></span>
								<input style="display:none;" id="FYDW" name="FYDW">
							</td>
						</tr>

						<tr>
							<td class="td-text">
								<label>服务内容：</label>
							</td>
							<td class="td-content" colspan="3">
								<input id="FWNR" name="FWNR" class="form-control dataField" type="text" style="width:95.6%;"
									   quick-config="label:'服务内容', validateProxy:'notNull length', length: '500'"
									   placeholder="服务内容">
							</td>
						</tr>

						<tr>
							<td class="td-text">
								<label>备注：</label>
							</td>
							<td class="td-content" colspan="5"> 
								<input id="BZ" name="BZ" class="form-control dataField" type="text" style="width:95.6%;"
									placeholder="备注">
							</td>
						</tr>
					</table>
					<!-- <div style="text-align: center;padding-top:10px;">
						<button class="btn btn-primary" type="button" id="btnSave" >提交</button>
						&nbsp;
						<button class="btn btn-default" type="button" onclick="btnBackHandler()">返回</button>
					</div> -->
			</form>
		</div>
</body>
</html>


